/**
*      author: Y_Yao
*      created: 2025-02-09 18:16:44
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 5e5 + 7;
int n,m,s;
vector<vector<int>> v(N);
int dep[N],f[N][20];

void dfs(int u,int father)
{
    dep[u] = dep[father] + 1;
    f[u][0] = father;

    for(int i = 1;i <= 19;i++)
    {
        f[u][i] = f[f[u][i-1]][i-1];
    }

    for(auto& e : v[u])
    {
        if(e == father) continue;
        dfs(e,u);
    }
}

int lca(int a,int b)
{
    if(dep[a] < dep[b]) swap(a,b);

    for(int i = 19;i >=0;i--)
    {
        if(dep[f[a][i]] >= dep[b])
        {
            a = f[a][i];
        }
    }

    if(a == b) return b;

    for(int i = 19;i >= 0;i--)
    {
        if(f[a][i] != f[b][i])
        {
            a = f[a][i];
            b = f[b][i];
        }
    }
    return f[a][0];
}

void solve()
{
    cin >> n >> m >> s;
    for(int i = 1;i < n;i++)
    {
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    dfs(s,0);
    while(m--)
    {
        int a,b;
        cin >> a >> b;
        int ret = lca(a,b);
        cout << ret << endl;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}